package com.heima.wemedia.controller.v1;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
@Api(value = "自媒体人管理",tags = "自媒体人管理")
public class WmMaterialController {

    @Autowired
    WmMaterialService wmMaterialService;

    @ApiOperation("文件上传")
    @PostMapping("/upload_picture")
    public ResponseResult upLoad(MultipartFile multipartFile) throws IOException {
        return wmMaterialService.upLoad(multipartFile);
    }

    @ApiOperation("素材列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) throws IOException {
        return wmMaterialService.materialList(dto);
    }

    @ApiOperation("添加收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult addCollection(@PathVariable Integer id) throws IOException {
        return wmMaterialService.collection(id,1);
    }

    @ApiOperation("取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollection(@PathVariable Integer id) throws IOException {
        return wmMaterialService.collection(id,0);
    }

    @ApiOperation("删除文件")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Integer id) throws IOException {
        return wmMaterialService.delete(id);
    }
}
